package vsa.migrations.junit.migrators;

import org.emftext.commons.layout.LayoutInformation;
import org.emftext.language.java.classifiers.Class;
import org.emftext.language.java.containers.CompilationUnit;
import org.emftext.language.java.members.Method;
import org.emftext.language.java.resource.java.grammar.JavaGrammarInformationProvider;

import vsa.migrations.junit.JunitMigrationException;

public class VisibilityMigrator extends AbstractJunitMigrator {


	@Override
	public void cleanupTestCase(CompilationUnit compilationunit, Class clazz)
			throws JunitMigrationException {
		// TODO Auto-generated method stub

	}

	@Override
	public void migrateTestCase(CompilationUnit compilationunit, Class clazz)
			throws JunitMigrationException {

		  for (Method nextMethod: clazz.getMethods()) {

		  	//make setup public
		  	if (nextMethod.getName().equals(METHODENAME_SETUP) && nextMethod.isProtected()) {
		  		LayoutInformation layoutinfo = nextMethod.getModifiers().get(0).getLayoutInformations().isEmpty() ? null : nextMethod.getModifiers().get(0).getLayoutInformations().get(0);
		  		nextMethod.makePublic();
		  		if (layoutinfo != null) {
		  			layoutinfo.setVisibleTokenText("public");
		  			layoutinfo.setSyntaxElementID(JavaGrammarInformationProvider.getSyntaxElementID(JavaGrammarInformationProvider.JAVA_122_0_0_0));
		  			nextMethod.getModifiers().get(0).getLayoutInformations().add(layoutinfo);
		  		}
		  	}

		  	//make tearDown public
		  	if (nextMethod.getName().equals(METHODENAME_TEARDOWN) && nextMethod.isProtected()) {
		  		LayoutInformation layoutinfo = nextMethod.getModifiers().get(0).getLayoutInformations().isEmpty() ? null : nextMethod.getModifiers().get(0).getLayoutInformations().get(0);
		  		nextMethod.makePublic();
		  		if (layoutinfo != null) {
		  			layoutinfo.setVisibleTokenText("public");
		  			layoutinfo.setSyntaxElementID(JavaGrammarInformationProvider.getSyntaxElementID(JavaGrammarInformationProvider.JAVA_122_0_0_0));
		  			nextMethod.getModifiers().get(0).getLayoutInformations().add(layoutinfo);
		  		}
		  	}
		  }

	}

}
